home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-03 / dosbasic.zip / ASM.ZIP / DOSVER.ASM < prev    next >
Assembly Source File  |  1990-12-19  |  6KB  |  159 lines

  1. ;«RM82»«TS8,16,24,32,40,48»updated 11/20/90
  2.  
  3. ;===========================================================================
  4. ;   Copyright (C) Copr. 1990 by Sidney J. Kelly
  5. ;                   All Rights Reserved.
  6. ;           Sidney J. Kelly
  7. ;           150 Woodhaven Drive
  8. ;           Pittsburgh, PA 15228
  9. ;           home phone 412-561-0950 (7pm to 9:30pm EST)
  10. ;===========================================================================
  11.  
  12. DOSSEG
  13. .model medium, BASIC
  14. .code
  15.  
  16. ; Please do not remove
  17. Copyright       DB    13,10,'Copyright Copr. (C) 1990 Sidney J. Kelly',13,10
  18. Copyright1      DB    'All Rights Reserved',13,10,26
  19.  
  20. ;===========================================================================
  21. ;DECLARE FUNCTION DOSVER% ()
  22. ;CALL DOSVER%
  23. ;Returns DOS VERSION value as an integer, to get display value \ 100
  24. ;E.g. DOS Version 3.3 is returned as 330
  25. ;===========================================================================
  26.  
  27. EVEN
  28. DOSVER PROC FAR BASIC
  29.         Mov     AH,30h
  30.         Int     21h
  31.         OR      AL,AL      ;test for Version 1.xx
  32.         JNE     adjust     ;if not equal then jump
  33.         Mov     AX,10
  34.         JMP     SHORT finis
  35. adjust:
  36.         Mov     BL,AL      ;multiply major value by 10
  37.         Mov     CL,3       ;using shifts for speed
  38.         SHL     AL,CL
  39.         SHL     BL,1
  40.         ADD     AL,BL      ;ADD values together
  41.         Mov     DH,AH
  42.  
  43.         XOR     BX,BX
  44.         XOR     AH,AH
  45.         Mov     BX,AX      ;multiply major value by 10 again
  46.         Mov     CL,3       ;using shifts for speed
  47.         SHL     AX,CL
  48.         SHL     BX,1
  49.         ADD     AX,BX      ;ADD values together
  50.  
  51.         XOR     BX,BX      ;clear BX
  52.         Mov     BL,DH      ;store DH in BL
  53.         ADD     AX,BX      ;ADD minor version
  54. finis:
  55.         ret
  56. DOSVER          Endp
  57.  
  58. ;===========================================================================
  59. ; DECLARE SUB MEM2STRING (TEXT$,SegAddress%,OffAddress%)
  60. ; Reads bytes from memory and stores them into a string
  61. ; number of bytes transferred is = LEN(Text$)
  62. ; Assumes string is in near data (DGROUP) & not a fixed length string
  63. ; or a user defined TYPE.
  64. ;===========================================================================
  65.  
  66. EVEN
  67. MEM2STRING Proc FAR BASIC USES DS SI DI, \
  68. TEXTSTRG:Ptr, Seg_Addr:Ptr, Off_Addr:Ptr
  69.  
  70.         Mov   AX,SS         ; Set up ES to point to DGROUP
  71.         Mov   ES,AX         ; for near strings
  72.  
  73.         ASSUME ES:@data     ; tell MASM of change
  74.  
  75.         Mov   BX,TEXTSTRG   ; put descriptor to TEXT$ into BX
  76.         Mov   CX,[BX]       ; put Len(TEXT$) into CX for loop counter
  77.         JCXZ  Exit3         ; if CX is zero it's a null string, exit now
  78.         Mov   DI,[BX+02]    ; put address of last character in X$ into DI
  79.         CLD                 ; Clear the direction flag to move data forward
  80.         Mov   BX,Off_Addr   ; get offset address
  81.         Mov   SI,[BX]       ; store in SI
  82.         Mov   BX,Seg_Addr   ; get segment address
  83.         Mov   DS,[BX]       ; store in DS.  Do this LAST because DS
  84.                 ; is used to address stack!!
  85.         ASSUME DS:NOTHING
  86.  
  87.         Rep   Movsb         ; rapidly move for source to TEXT$
  88. Exit3:
  89.         Ret                 ; MASM automatically restores the balance
  90. MEM2STRING Endp
  91.  
  92. ;===========================================================================
  93. ; DECLARE FUNCTION MEM2INT% (SegAddress%,OffAddress%)
  94. ; Reads word from memory and returns an integer value
  95. ; Faster than PEEK(High_byte) * 256 + PEEK(Low_byte)
  96. ;===========================================================================
  97.  
  98. EVEN
  99. MEM2INT Proc FAR BASIC , \
  100. Seg_Addr:Ptr, Off_Addr:Ptr
  101.  
  102.     XOR   DX,DX          ; clear DX in case function is defined as long&
  103.     Mov   BX,Seg_Addr    ; get segment address
  104.     Mov   BX,[BX]        ; store temporarily in BX
  105.     Mov   ES,BX
  106.     Mov   BX,Off_Addr    ; get offset address
  107.     Mov   BX,[BX]        ; store temporarily in BX
  108.     Mov   BX,ES:[BX]     ; read ES:[BX] into BX
  109.     Mov   AX,BX
  110.     Ret                  ; MASM automatically restores the balance
  111. MEM2INT Endp
  112.  
  113.  
  114. COMMENT         |
  115. ===========================================================================
  116. DECLARE SUB GETDOSVER (VERSION$)
  117.  
  118.         VERSION$=SPACE$(4)
  119.         CALL GETDOSVER(VERSION$)
  120. Returns DOS Version as a string
  121. ===========================================================================
  122.         |
  123.  
  124. EVEN
  125. GETDOSVER Proc Far BASIC, VERS:Ptr
  126.           Mov            AH,30h         ; function to get the DOS version
  127.           Int            21h            ; execute the function
  128.                         ; we now have the major version
  129.                         ; number in AL and the minor
  130.                         ; version number in AH
  131.           OR             AL,AL          ; test for Version 1.xx
  132.           JNE            Adjust1        ; if not equal then make ver 1
  133.           Mov            AX,10
  134. Adjust1:
  135.           Mov            CL,AH          ; put minor version # in CL
  136.           Mov            CH,0           ; convert from a byte to a word
  137.           Mov            AH,0           ; convert AL from byte to word
  138.  
  139.           Mov            BX,VERS        ; get address of the string info
  140.           CMP  Word Ptr  [BX],4         ; is VERSION$ long enough?
  141.           JB             Done           ;   no, it's too short-- exit
  142.  
  143.           Mov            BX,[BX+2]      ; get address of VERSION$ itself
  144.  
  145.           ADD            AL,"0"         ; convert major version # to ASCII
  146.           Mov            [BX],AL        ; store it in VERSION$
  147.           Inc            BX             ; move to the next character
  148.           Mov Byte Ptr   [BX],"."       ; store decimal point in VERSION$
  149.           Inc            BX             ; move to the next character
  150.           Mov            AL,CL          ; put the minor version in AL
  151.           AAM                           ; convert to digits in AL and AH
  152.           XCHG           AL,AH          ; put digits in correct order
  153.           ADD            AX,"00"        ; convert minor version # to ASCII
  154.           Mov            [BX],AX        ; store it in VERSION$
  155. Done:
  156.           Ret
  157. GETDOSVER     Endp
  158. END
  159.